package com.henry.learngui;

import javafx.application.Application;
import javafx.concurrent.Task;
import javafx.geometry.Pos;
import javafx.stage.Stage;
import javafx.scene.text.Text;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.layout.Background;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;

public class HelloGoodbye extends Application
{
    private Text text = new Text(60, 240, "Hello");
    public void start (Stage stage)
    {
        text.setFont(Font.font ("Verdana", 25));
        text.setFill(Color.BLUE);
        VBox root = new VBox();
        root.setBackground(Background.EMPTY);
        root.setAlignment(Pos.CENTER);
        root.getChildren().add(text);
        Scene scene = new Scene(root, 200, 200);
        stage.setScene(scene);
        stage.setTitle("Hello-Goodbye");
        stage.show();
        begin(stage);
    }
    private void begin(Stage stageIn)
    {
        Thread thread1 = new Thread(new Task<Void>()
        {
            protected Void call()
            {
                while (stageIn.isShowing()) {
                    text.setText("Hello!");
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    text.setText("Goodbye!");
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("Bye!");
                return null;
            }
        });
        thread1.start();
    }
    public static void main(String[] args)
    {
        launch(args);
    }
}
